package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo14 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();) {
            connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
            connection.setAutoCommit(false);

            String sql = "INSERT INTO userinfo(username,password,nickname,age) " +
                    "VALUES (?,?,?,? )";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, "夜刀神十香");
            preparedStatement.setString(2, "123456");
            preparedStatement.setString(3, "十香");
            preparedStatement.setInt(4, 18);
            int count = preparedStatement.executeUpdate();
            System.out.println(count > 0 ? "注册成功" : "注册失败");

            connection.rollback();

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
